<?php

    class BabooDatabase extends Database {
        /* Baboo Enhancements */
        public function FetchTables() {
            $res = $this->Query( 'SHOW TABLES FROM ' . $this->mDbName );
            while ( $row = $res->FetchArray( false ) ) {
                $table = $row[ 0 ];
                $this->AttachTable( $table, $table );
            }

            return $this->mTables;
        }
        public function AllDatabases() {
            if ( empty( $this->mAllDatabases ) ) {
                $res = $this->Query( 'SHOW DATABASES' );
                while ( $row = $res->FetchArray() ) {
                    $this->mAllDatabases[] = $row[ 'Database' ];
                }
            }
            return $this->mAllDatabases;
        }
        public function SwitchToFirstDb() {
            $databases = $this->AllDatabases();
            if ( count( $databases ) > 0 ) {
                $this->SwitchDb( $databases[ 0 ] ); 
            }
        }
        public function Username() {
            return $this->mUsername;
        }
        public function TestConnect() {
            if ( $this->mDriver->Connect( $this->mHost , $this->mUsername , $this->mPassword , false ) === false ) {
                return false;
            }
            return true;
        }
        public function CreateDb( $name ) {
            return $this->Query( "CREATE DATABASE " . $name )->Impact();
        }
    }

?>
